package ru.lenwp.operation.admin;

import ru.lenwp.context.Context;
import ru.lenwp.model.Admin;
import ru.lenwp.model.Client;
import ru.lenwp.model.OperationInfo;
import ru.lenwp.model.User;
import ru.lenwp.operation.Operation;

import java.util.Scanner;

/**
 * @author: sk_y
 */
public class CreateNewUserOperation implements Operation {
    private final Context context;

    public CreateNewUserOperation(Context context) {
        this.context = context;
    }

    @Override
    public OperationInfo execute() {
        context.getUserDao().insert(createUser());
        return null;
    }

    public static User createUser() {
        System.out.println("Введите тип пользователя:");
        System.out.println("1.Администратор");
        System.out.println("2.Клиент");
        Scanner sc = new Scanner(System.in);
        return createUserByInputNumber(sc.nextInt());
    }

    private static User createUserByInputNumber(int inputNumber) {
        switch (inputNumber) {
            case 1:
                return Admin.createUser();
            case 2:
                return Client.createClient();
            default:
                throw new RuntimeException("Не верно введен тип пользователя ");
        }
    }


    @Override
    public String getOperationName() {
        return "Создание нового пользователя";
    }
}
